<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="./libs/react.js"></script>
    <script src="./libs/react-dom.js"></script>
    <script src="./libs/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;

      class Counter extends Component {
        constructor(props) {
          super(props);
          this.state = {
            childCount: 0,
          };
          this.clickHandle = this.clickHandle.bind(this);
        }
        clickHandle() {
          this.setState(
            {
              childCount: this.state.childCount + 1,
            },
            function () {
              this.props.changeFather(this.state.childCount);
            }
          );
        }
        render() {
          return (
            <div>
              <button onClick={this.clickHandle}>
                点击{this.state.childCount}
              </button>
            </div>
          );
        }
      }

      class App extends Component {
        constructor(props) {
          super(props);
          this.state = {
            parentCount: 0,
          };
          this.changeFromChild = this.changeFromChild.bind(this);
        }
        changeFromChild(v) {
          this.setState({
            parentCount: v,
          });
        }
        render() {
          return (
            <div>
              <p>父组件中显示子组件中的count值为：{this.state.parentCount}</p>
              <Counter changeFather={this.changeFromChild} />
            </div>
          );
        }
      }
      ReactDOM.render(<App />, document.getElementById("app"));
    </script>
  </body>
</html>
